package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup
var total int
var	rwlock sync.RWMutex

func read()  {
	defer wg.Done()
	rwlock.RLock()
	fmt.Println("开始读取数据")
	time.Sleep(time.Second)
	fmt.Println("读取成功")
	rwlock.RUnlock()
}
func write() {
	defer wg.Done()
	rwlock.Lock()
	fmt.Println("开始修改数据")
	time.Sleep(time.Second*10)
	fmt.Println("修改成功")
	rwlock.Unlock()
}
func main()  {

	wg.Add(6) //因为启动六个子协程，故计数为2
	for i:=0;i<5;i++ {
		go read()
	}
	for i:=0;i<1;i++ {
		go write()
	}
	wg.Wait()
	fmt.Println(total)
}
